#include "stdafx.h"
#include "superelement.hpp"

//-----------------------------------------------------------
FElement::FElement ()
  : vertex0_coord_(0), vertex1_coord_(0), midpoint_(0), index_(0), level_(0),
 vertex0_index_(0), vertex1_index_(0), midpoint_index_(0), father_(0) {; }

FElement::~FElement ()
{}

void FElement::fill (const double& vertex0_coord, const double& vertex1_coord, 
	const myindex vertex0_index, const myindex vertex1_index, 
	const myindex midpoint_index, const myindex level, const myindex idx,
	const myindex father)
{
  index_ = idx;
  level_ = level;
  vertex0_index_ = vertex0_index;
  vertex1_index_ = vertex1_index;
  father_ = father;

  vertex0_coord_ = vertex0_coord;
  vertex1_coord_ = vertex1_coord;

  midpoint_index_ = midpoint_index;

  area_ = vertex1_coord - vertex0_coord;

  midpoint_ = (vertex0_coord_ + vertex1_coord_)*0.5;
}

myindex FElement::getIndex () const
{return this->index_;}

myindex FElement::getLevel () const
{return this->level_;}

myindex FElement::getVertexIndex (myindex idx) const
{
  switch (idx)
  {
  case 0:
    return this->vertex0_index_;
    break;
  case 1:
    return this->vertex1_index_;
    break;
  default:
    throw std::out_of_range ("FElement::getVertexIndex: illigal index");
  }
}

myindex FElement::getMidpointIndex () const
{return this->midpoint_index_;}

myindex FElement::getFather () const
{return this->father_;}

double FElement::getVertexCoord (myindex idx) const
{
  switch (idx)
  {
  case 0:
    return this->vertex0_coord_;
    break;
  case 1:
    return this->vertex1_coord_;
    break;
  default:
    throw std::out_of_range ("FElement::getVertexCoord: illigal index");
  }
}

double FElement::getArea () const
{return this->area_;}

double FElement::getMidpoint () const
{return this->midpoint_;}

void FElement::printFE()
{
  std::cout << "Information of element " << this->index_ << ": " << std::endl;
  std::cout << "The first and the second points of element: " << this->vertex0_coord_ << "  , " << this->vertex1_coord_ << std::endl;
  std::cout << "The first and the second indices of element: " << this->vertex0_index_ << "  , " << this->vertex1_index_ << std::endl;
}

std::ostream& operator<< (std::ostream& s, const FElement& el)
{
  s << "index: " << el.getIndex() << " level: " << el.getLevel() <<  " father: " << el.getFather();
  s << " vertices: " << el.getVertexIndex(0) << " " << el.getVertexIndex(1) << std::endl;

  return (s);
}